package com.varian.mybatis.base;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Optional;

/**
 * @author ben
 * @since 2024/6/23
 */
public abstract class BaseServiceImpl<M extends BaseMapper<E>, E extends PrimaryKeyEntity> extends ServiceImpl<M, E> implements IBaseService<E> {


    protected E validateExistence(Long id) {
        throw new UnsupportedOperationException("validateExistence not yet implemented");
    }

    protected void validateUniqueness(E entity) {
        throw new UnsupportedOperationException("validateUniqueness not yet implemented");
    }

    protected Optional<E> saveOpt(E entity) {
        return save(entity) ? Optional.of(entity) : Optional.empty();
    }

    protected Optional<E> updateOpt(E entity) {
        return updateById(entity) ? Optional.of(entity) : Optional.empty();
    }
}
